package jnpf.base.model.dblink;

import io.swagger.annotations.ApiModelProperty;
import jnpf.database.entity.DbLinkEntity;
import jnpf.util.JsonUtil;
import lombok.Data;

import javax.validation.constraints.NotBlank;

/**
 * 数据库基础表单对象
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2021/3/12 15:31
 */
@Data
public class DbLinkBaseForm {

    @ApiModelProperty(value = "连接名")
    @NotBlank(message = "必填")
    private String fullName;

    @ApiModelProperty(value = "数据库类型编码")
    @NotBlank(message = "必填")
    private String dbType;

    @ApiModelProperty(value = "用户")
    @NotBlank(message = "必填")
    private String userName;

    @ApiModelProperty(value = "数据库名")
    private String serviceName;

    @ApiModelProperty(value = "密码")
    @NotBlank(message = "必填")
    private String password;

    @ApiModelProperty(value = "端口")
    @NotBlank(message = "必填")
    private String port;

    @ApiModelProperty(value = "ip地址")
    @NotBlank(message = "必填")
    private String host;

    @ApiModelProperty(value = "模式")
    private String dbSchema;

    @ApiModelProperty(value = "表空间")
    private String tableSpace;

    /**
     * 根据表单对象返回连接实体类
     * @param dbLinkBaseForm 连接表单对象
     * @return 连接实体对象
     */
    public DbLinkEntity getDbLinkEntity(DbLinkBaseForm dbLinkBaseForm){
        DbLinkEntity entity = JsonUtil.getJsonToBean(dbLinkBaseForm, DbLinkEntity.class);
        entity.setDbName(dbLinkBaseForm.getServiceName());
        return entity;
    }

}
